<html>
	<head>
		<title>Logged in</title>

		<script type="text/javascript">
		function flag(x,mark)
		{
			var append="";
			var url = 'http://vark.myrpi.org/flag.php?path=' + x + '&flag=' + mark;
		
			if (window.XMLHttpRequest) {
				ajax = new XMLHttpRequest();
			} 

			ajax.onreadystatechange=function()	{
				ajax.timeout = '1';
	
					if(ajax.readyState == 4)	{
						append = "<input id='"+x+"' type='checkbox' onclick='flag(this.id," + ajax.responseText + ")' ";
						
						if(ajax.responseText == 1)
							append += "' checked='checked'";
						append += " />";
						document.getElementById("td_" + x).innerHTML = append;
						append = "";
					}
			
			}
		
			ajax.open("GET",url);
			ajax.send();
		
		}

		</script>

	</head>
	<body>
	
<?php

	$order = array('crawl_id','full_path','date','flag');

	$conn =  mysql_connect("localhost", "vandes4_root", 'root');
	
	if ($conn)	{
	
	 	$db=mysql_select_db('vandes4_PROJECT', $conn);
	 	
	 	if ($db)	{
	 	
	 		$query = "SELECT crawl_id,full_path,date,flag FROM crawl;";
	 		$exec = mysql_query($query);
			
			echo "<table border=1>";
			
			echo "<th>Crawl ID</th>";
			echo "<th>Path</th>";
			echo "<th>Last Date Crawled</th>";
			echo "<th>Flagged</th>";
//			if($admin)	echo "<th>Remove?</th>";
			
			
			while($read = mysql_fetch_array($exec))	{
				
				$_SESSION['data'] = $read['flag'];
				$path = $read['full_path'];
				echo "<tr>";
				$end = 0;
				if($admin) $end = 3;
				else $end = 4;
				
				
				for ($i = 0; $i < $end; $i++)	{				
					echo "<td class='".$path."'>".$read[$i]."</td>";				
				}
				
				if($admin)	{
				
					echo "<td id='td_".$path."'>"."<input id='".$path."'type='checkbox' onclick='flag(this.id,".$_SESSION['data'].")' ";
					$read['flag'] = $_SESSION['data'];
					if($read['flag'] == 1)
						echo "' checked='checked'";
					echo " /></td>";
				
				}
				
				echo "</tr>";
			
			}		
			
			echo "</table>";

			
		}
	}

?>
	</body>
</html>